package com.hp.attendance.serlvet.empmanage.zaizhi;

import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.History;
import com.hp.attendance.service.EmployeeService;
import com.hp.attendance.service.HistoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/historyZZUpdate")
public class EmpManageZZHistoryUpdateServlet extends HttpServlet {
    private HistoryService historyService = new HistoryService();
    private EmployeeService employeeService = new EmployeeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            int employee_number = Integer.parseInt(req.getParameter("employeeNumber"));//工号
            int id = Integer.parseInt(req.getParameter("id"));
            String name = req.getParameter("name");//姓名
            String password = req.getParameter("password");//姓名
            String gender = req.getParameter("gender");//性别
            String brithday = req.getParameter("date");//出生年日
            Date birthday1 = null;
            try {
                birthday1 = new SimpleDateFormat("yyyy-MM-dd").parse(brithday);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String telephone = req.getParameter("telephone");//联系方式
            String email = req.getParameter("email");//邮箱
            String address = req.getParameter("address");//籍贯
            String education = req.getParameter("education");//学历
            int department_number = Integer.parseInt(req.getParameter("departmentNumber"));//部门
            int position_number = Integer.parseInt(req.getParameter("positionNumber"));//职称
            String notes = req.getParameter("notes");//备注
            String status = req.getParameter("status");//状态
            Employee employee = new Employee(id, name, gender, birthday1, telephone, email, address, education,department_number,position_number,password, notes);
            History history = new History(employee_number, name, gender, birthday1, telephone, email, address, department_number,position_number,status,education, notes);
            employeeService.empUpdate(employee);
            historyService.historyUpdate1(history);
            req.getRequestDispatcher("/empMangeZZList").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
